/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package QLNV.Bean;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import java.util.*;
import QLNV.Entity.*;
import QLNV.Utilities.*;
import java.sql.*;


/**
 *
 * @author Ice
 */
public class KhenThuongKyLuatForm extends org.apache.struts.action.ActionForm {
    
    private String name;
    private int number;
    private String maktkl;
    private String manv;
    private String tenktkl;
    private String hinhthucktkl;
    private String ngaythang;

    /**
     * @return
     */
    public String getName() {
        return name;
    }

    /**
     * @param string
     */
    public void setName(String string) {
        name = string;
    }

    /**
     * @return
     */
    public int getNumber() {
        return number;
    }

    /**
     * @param i
     */
    public void setNumber(int i) {
        number = i;
    }

    /**
     *
     */
    public KhenThuongKyLuatForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (getName() == null || getName().length() < 1) {
            errors.add("name", new ActionMessage("error.name.required"));
            // TODO: add 'error.name.required' key to your resources
        }
        return errors;
    }

    /**
     * @return the maktkl
     */
    public String getMaktkl() {
        return maktkl;
    }

    /**
     * @param maktkl the maktkl to set
     */
    public void setMaktkl(String maktkl) {
        this.maktkl = maktkl;
    }

    /**
     * @return the manv
     */
    public String getManv() {
        return manv;
    }

    /**
     * @param manv the manv to set
     */
    public void setManv(String manv) {
        this.manv = manv;
    }

    /**
     * @return the tenktkl
     */
    public String getTenktkl() {
        return tenktkl;
    }

    /**
     * @param tenktkl the tenktkl to set
     */
    public void setTenktkl(String tenktkl) {
        this.tenktkl = tenktkl;
    }

    /**
     * @return the hinhthucktkl
     */
    public String getHinhthucktkl() {
        return hinhthucktkl;
    }

    /**
     * @param hinhthucktkl the hinhthucktkl to set
     */
    public void setHinhthucktkl(String hinhthucktkl) {
        this.hinhthucktkl = hinhthucktkl;
    }

    /**
     * @return the ngaythang
     */
    public String getNgaythang() {
        return ngaythang;
    }

    /**
     * @param ngaythang the ngaythang to set
     */
    public void setNgaythang(String ngaythang) {
        this.ngaythang = ngaythang;
    }
    
    /**
     * view
     * @return
     * @throws SQLException 
     */
    public ArrayList<KhenThuongKyLuat> view() throws SQLException {
        ArrayList<KhenThuongKyLuat> ktklList = new ArrayList<KhenThuongKyLuat>();
        try {
            Conn cnn = new Conn();
            String sql = "select * from khenthuongkyluat";
            ResultSet rs = cnn.exec(sql);
            if (rs != null) {
                while (rs.next()) {
                    KhenThuongKyLuat ktkl = new KhenThuongKyLuat();
                    ktkl.setMaktkl(rs.getString("maktkl"));
                    
                    NhanVien nv = new NhanVien();
                    nv.setManv(rs.getString("manv"));
                    
                    ktkl.setNv(nv);
                    ktkl.setTenktkl(rs.getString("tenktkl"));
                    ktkl.setHinhthucktkl(rs.getString("hinhthucktkl"));
                    ktkl.setNgaythang(rs.getString("ngaythang"));
                    
                    ktklList.add(ktkl);
                }
            }
            cnn.close();
        } catch (SQLException e) {
            e.getMessage();
        }
        return ktklList;
    }
    
    
    
    /**
     * insert khenthuongkyluat
     * @param maktkl
     * @param manv
     * @param tenktkl
     * @param hinhthucktkl
     * @param ngaythang
     * @return
     * @throws SQLException 
     */
     public String insert(String maktkl, String manv, String tenktkl, String hinhthucktkl, String ngaythang) throws SQLException {
        String message = "";
        try {
            DBHelper.getInstance().initConnection();
            ArrayList<String> arr = new ArrayList<String>();

            arr.add(maktkl);
            arr.add(manv);
            arr.add(tenktkl);
            arr.add(hinhthucktkl);
            arr.add(ngaythang);
            message = DBHelper.getInstance().executeUpdateProcReturn("Insert_KhenThuongKyLuat", arr);
        } catch (Exception e) {
            e.getMessage();
        }
        return message;
    }
     
     /**
      * delete khenthuongkyluat
      * @param manv
      * @return
      * @throws SQLException 
      */
     public int delete(String maktkl) throws SQLException {
        Conn cnn = new Conn();
        String sql_delete = "delete from khenthuongkyluat where maktkl='" + maktkl + "'";
        int cnt = cnn.delete(sql_delete);
        return cnt;
    }
     
     /**
      * detail
      * @param maktkl
      * @return
      * @throws SQLException 
      */
     public ArrayList<KhenThuongKyLuat> detail(String maktkl) throws SQLException {
        ArrayList<KhenThuongKyLuat> ktklList = new ArrayList<KhenThuongKyLuat>();
        try {
            Conn cnn = new Conn();
            String sql = "select * from khenthuongkyluat where maktkl='" + maktkl + "'";
            ResultSet rs = cnn.exec(sql);
            if (rs != null) {
                while (rs.next()) {
                    KhenThuongKyLuat ktkl = new KhenThuongKyLuat();
                    ktkl.setMaktkl(rs.getString("maktkl"));
                    NhanVien nv = new NhanVien();
                    nv.setManv(rs.getString("manv"));
                    ktkl.setNv(nv);
                    ktkl.setTenktkl(rs.getString("tenktkl"));
                    ktkl.setHinhthucktkl(rs.getString("hinhthucktkl"));
                    ktkl.setNgaythang(rs.getString("ngaythang"));
                    ktklList.add(ktkl);
                }
            }
            cnn.close();
        } catch (SQLException e) {
            e.getMessage();
        }
        return ktklList;
    }
     
     
     /**
      * update
      * @param maktkl
      * @param manv
      * @param tenktkl
      * @param hinhthucktkl
      * @param ngaythang
      * @return
      * @throws SQLException 
      */
     public ArrayList<KhenThuongKyLuat> update(String maktkl, String manv, String tenktkl, String hinhthucktkl, String ngaythang) throws SQLException {
        DBHelper.getInstance().initConnection();
        ArrayList<String> arr = new ArrayList<String>();
        ArrayList<KhenThuongKyLuat> ktklList  = new ArrayList<KhenThuongKyLuat>();
        arr.add(maktkl);
        arr.add(manv);
        arr.add(tenktkl);
        arr.add(hinhthucktkl);
        arr.add(ngaythang);
        ResultSet rs = DBHelper.getInstance().executeQueryProc("Update_KhenThuongKyLuat", arr);
        if (rs != null) {
            while (rs.next()) {
                    KhenThuongKyLuat ktkl = new KhenThuongKyLuat();
                    ktkl.setMaktkl(rs.getString("maktkl"));
                    NhanVien nv = new NhanVien();
                    nv.setManv(rs.getString("manv"));
                    ktkl.setNv(nv);
                    ktkl.setTenktkl(rs.getString("tenktkl"));
                    ktkl.setHinhthucktkl(rs.getString("hinhthucktkl"));
                    ktkl.setNgaythang(rs.getString("ngaythang"));
                    ktklList.add(ktkl);
                }
        }
        return ktklList;
    }
     
     /**
      * search
      * @param maktkl
      * @return
      * @throws SQLException 
      */
     public ArrayList<KhenThuongKyLuat> search(String maktkl) throws SQLException {
        //KhenThuongKyLuat ktkl = new KhenThuongKyLuat();
        ArrayList<KhenThuongKyLuat> ktklList = new ArrayList<KhenThuongKyLuat>();
        DBHelper.getInstance().initConnection();
        ArrayList<String> arr = new ArrayList<String>();
        arr.add(maktkl);
        ResultSet rs = DBHelper.getInstance().executeQueryProc("Search_KhenThuongKyLuat", arr);
        if (rs != null) {
            while (rs.next()) {
                ResultSetMetaData rsmd = rs.getMetaData();
                int numberOfColumns = rsmd.getColumnCount();
                if (numberOfColumns == 1) {
                    
                } else {
                    KhenThuongKyLuat ktkl = new KhenThuongKyLuat();
                    ktkl.setMaktkl(rs.getString("maktkl"));
                    NhanVien nv = new NhanVien();
                    nv.setManv(rs.getString("manv"));
                    ktkl.setNv(nv);
                    ktkl.setTenktkl(rs.getString("tenktkl"));
                    ktkl.setHinhthucktkl(rs.getString("hinhthucktkl"));
                    ktkl.setNgaythang(rs.getString("ngaythang"));
                    ktklList.add(ktkl);
                }
            }
        }
        return ktklList;
        //String message = DBHelper.getInstance().executeUpdateProcReturn("Search_PhongBan", arr);

    }
}
